﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using BLL;
using EDM;
using System.ServiceModel;
using System.ServiceModel.Description;


namespace Hosting
{
    public partial class TraningService : ServiceBase
    {
        ServiceHost host1;
        ServiceHost host2;


        public TraningService()
        {
            InitializeComponent();
            host1 = new ServiceHost(typeof(RoleService));
            host2 = new ServiceHost(typeof(StatusTextService));
        }




        protected override void OnStart(string[] args)
        {

            host1.AddServiceEndpoint(typeof(IRoleService), new WSHttpBinding(), "http://localhost:4269/RoleService");

            host2.AddServiceEndpoint(typeof(IStatusTextService), new WSHttpBinding(), "http://localhost:4269/StatusTextService");



            if (host1.Description.Behaviors.Find<ServiceMetadataBehavior>() == null)
            {
                ServiceMetadataBehavior behavior = new ServiceMetadataBehavior();
                behavior.HttpGetEnabled = true;
                behavior.HttpGetUrl = new Uri("http://localhost:4269/RoleService/metadata");
                host1.Description.Behaviors.Add(behavior);
            }


            host1.Open();



            if (host2.Description.Behaviors.Find<ServiceMetadataBehavior>() == null)
            {
                ServiceMetadataBehavior behavior1 = new ServiceMetadataBehavior();
                behavior1.HttpGetEnabled = true;
                behavior1.HttpGetUrl = new Uri("http://localhost:4269/StatusTextService/metadata");
                host2.Description.Behaviors.Add(behavior1);
            }

            host2.Open();
        }



        protected override void OnStop()
        {
            host1.Close();
            host2.Close();
        }
    }
}
